/************************************************************************
 * @file StandardAboutDialog.cpp
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#include <QFormLayout>
#include <QHBoxLayout>
#include <QIcon>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>

#include <pluginui/widget/StandardAboutDialog.h>

namespace antu
{
namespace plugin
{
namespace ui
{
StandardAboutDialog::StandardAboutDialog(const QString &title,
                                         const QString &productName,
                                         const QString &version,
                                         const QString &serialNumber,
                                         const QPixmap &image,
                                         QWidget *parent)
    : QDialog(parent)
{
    this->setWindowTitle(title);
    this->m_pImageLabel = new QLabel(this);

    if (image.isNull())
        this->m_pImageLabel->setPixmap(QPixmap(":/resources/images/ais.jpg"));
    else
        this->m_pImageLabel->setPixmap(image);

    this->m_pProductNameLabel = new QLabel(this);
    this->m_pProductNameLabel->setText(productName);

    this->m_pSerialNumberLabel = new QLabel(this);
    this->m_pSerialNumberLabel->setText(serialNumber);

    this->m_pVersionLabel = new QLabel(this);
    this->m_pVersionLabel->setText(version);

    QVBoxLayout* pMainLayout = new QVBoxLayout;
    QFormLayout* pProductLayout = new QFormLayout;
    QHBoxLayout* pBottomLayout = new QHBoxLayout;

    pProductLayout->addRow(new QLabel(tr("Product: "), this), this->m_pProductNameLabel);
    pProductLayout->addRow(new QLabel(tr("Version: "), this), this->m_pVersionLabel);
    pProductLayout->addRow(new QLabel(tr("Serial Number: "), this), this->m_pSerialNumberLabel);

    QTextEdit* pEdit = new QTextEdit(tr("Warning: This computer program is protected by copyright law and international treaties. Unauthorized reproduction or distribution of this program, or any portion of it, may result in severe civil and criminal penalties, and will be prosecuted under the maximum extent possible under law."),
        this);
    pEdit->setEnabled(false);

    QString copyright = QChar(0xA9) + tr("Beijing Antu Technologies Co., Ltd.");
    copyright[0] = QChar(0x00A9);
    pBottomLayout->addWidget(new QLabel(copyright));
    pBottomLayout->addStretch(1);
    QPushButton* pButton = new QPushButton;
    pButton->setText(tr("Ok"));

    pBottomLayout->addWidget(pButton);
    this->connect(pButton, SIGNAL(clicked()), this, SLOT(close()));

    QFrame* pFrame = new QFrame(this);
    pFrame->setFrameShape(QFrame::HLine);
    pFrame->setFrameShadow(QFrame::Sunken);
    pMainLayout->addWidget(this->m_pImageLabel);
    pMainLayout->addWidget(pEdit);
    pMainLayout->addLayout(pProductLayout);
    pMainLayout->addWidget(pFrame);
    pMainLayout->addLayout(pBottomLayout);

    this->setLayout(pMainLayout);
    this->setWindowIcon(QIcon(":/resources/images/about.png"));
}

}
}
}

